using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace WebDauGia.Domain.Models.Mapping
{
    public class SanPhamMap : EntityTypeConfiguration<SanPham>
    {
        public SanPhamMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.ten)
                .IsRequired();

            this.Property(t => t.mausac)
                .HasMaxLength(100);

            this.Property(t => t.kichthuoc)
                .HasMaxLength(100);

            this.Property(t => t.trongluong)
                .HasMaxLength(100);

            this.Property(t => t.ImageMimetype)
                .HasMaxLength(100);
            // Table & Column Mappings
            this.ToTable("SanPhams");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.ten).HasColumnName("ten");
            this.Property(t => t.idloaisp).HasColumnName("idloaisp");
            this.Property(t => t.mota).HasColumnName("mota");
            this.Property(t => t.idhangsx).HasColumnName("idhangsx");
            this.Property(t => t.ngaybatdau).HasColumnName("ngaybatdau");
            this.Property(t => t.ngayketthuc).HasColumnName("ngayketthuc");
            this.Property(t => t.tinhtrang).HasColumnName("tinhtrang");
            this.Property(t => t.mausac).HasColumnName("mausac");
            this.Property(t => t.kichthuoc).HasColumnName("kichthuoc");
            this.Property(t => t.trongluong).HasColumnName("trongluong");
            this.Property(t => t.idnguoiban).HasColumnName("idnguoiban");
            this.Property(t => t.giaban).HasColumnName("giaban");
            this.Property(t => t.giakhoidiem).HasColumnName("giakhoidiem");
            this.Property(t => t.active).HasColumnName("active");
            this.Property(t => t.ImageData).HasColumnName("ImageData");
            this.Property(t => t.ImageMimetype).HasColumnName("ImageMimetype");
            // Relationships
            this.HasOptional(t => t.HangSanXuat)
                .WithMany(t => t.SanPhams)
                .HasForeignKey(d => d.idhangsx);
            this.HasOptional(t => t.KhachHang)
                .WithMany(t => t.SanPhams)
                .HasForeignKey(d => d.idnguoiban);
            this.HasRequired(t => t.LoaiSanPham)
                .WithMany(t => t.SanPhams)
                .HasForeignKey(d => d.idloaisp);
            this.HasRequired(t => t.LoaiSanPham1)
                .WithMany(t => t.SanPhams1)
                .HasForeignKey(d => d.idloaisp);

        }
    }
}
